﻿using ControleRepresentante.Data.Catalogs;
using ControleRepresentante.Data.Helpers;

namespace ControleRepresentante.Data.CatalogSteps
{
    internal class CreateAttributeCatalogStep : CatalogStepBase<ControleRepresentanteCatalogStepTypes>
    {
        protected override ControleRepresentanteCatalogStepTypes CatalogStepType
        {
            get { return ControleRepresentanteCatalogStepTypes.CreateAttribute; }
        }

        public override void Execute(IDataAccess dataAccess)
        {
            CatalogStepHelper catalogStepHelper = new CatalogStepHelper(dataAccess);

            catalogStepHelper
                .CreateTable("Attribute")
                    .AddColumn("RepresentanteId", ColumnType.Guid, false, false)
                    .AddForeignKey("RepresentanteId", "Representante")
                    .AddColumn("Type", ColumnType.ShortNumeric, false, false)
                    .AddColumn("Name", ColumnType.ShortString, false, false);

            catalogStepHelper
                .CreateTable("AttributeValue")
                    .AddColumn("AttributeId", ColumnType.Guid, false, false)
                    .AddForeignKey("AttributeId", "Attribute")
                    .AddColumn("AttributeHolderId", ColumnType.Guid, false, false)
                    .AddForeignKey("AttributeHolderId", "AttributeHolder")
                    .AddColumn("Value", ColumnType.LongString, true, false);
        }
    }
}